#ifndef _ICODECELL_H_
#define _ICODECELL_H_

#include <BImage>
#include <BRect>
#include <BQuad>
#include "member_BFont.h"

namespace BWE
{
	class CodeCell
	{
	public:
		inline CodeCell()
		{
			code = 0;
			image = 0;
			image_left = 0;
			image_top = 0;
		}
		inline CodeCell(const BCode& c)
		{
			code = c;
			image = 0;
			image_left = 0;
			image_top = 0;
		}
		inline CodeCell(int x, int y, int w, int h)
		{
			rect.set(x, y, w, h);
			code = 0;
			image = 0;
			image_left = 0;
			image_top = 0;
		}
		inline CodeCell(const CodeCell& other)
		{
			code = other.code;
			rect = other.rect;
			image = other.image;
			image_left = other.image_left;
			image_top = other.image_top;
			image_rect = other.image_rect;
		}

		inline void fresh(const BFont* font, int rowHeight)
		{
			rect.setSize(3, rowHeight);
			image = 0;
			image_left = 0;
			image_top = 0;
			image_rect.setSize(0, 0);
			if (font)
			{
				if (rowHeight < 1)
					rowHeight = font->size();

				BSize size = font->codeSize(code);
				rect.setSize(size.width(), rowHeight);

				CodeInfo* info = font_member(font)->getCodeInfo(code);
				if (info && info->image)
				{
					BImage* img = info->image;
					image = img;
					image_left = info->left;
					image_top = info->top;
					image_rect.setSize(img->width(), img->height());
				}
			}
		}

		inline bool operator == (const BCode& code)
		{
			return this->code == code;
		}
		inline bool operator != (const BCode& code)
		{
			return this->code != code;
		}

		BCode			code;
		BRect			rect;
		int				image_left;
		int				image_top;
		BRect			image_rect;
		BImageHolder	image;
	};

}

#endif